package com.lmt_11;

import com.lmt_5.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest2 {
    public static void main(String[] args) {
        List<Double> scores = new ArrayList<>();
        Collections.addAll(scores,88.5,100.0,60.0,99.0,99.6);

        List<Student> students = new ArrayList<>();
        students.add(new Student("蜘蛛精",26));
        students.add(new Student("蜘蛛精",26));
        students.add(new Student("紫霞",23));
        students.add(new Student("白晶晶",25));
        students.add(new Student("牛魔王",35));
        students.add(new Student("牛夫人",34));

        // 找出成绩大于60的数据
        scores.stream().filter(s -> s > 60.0).forEach(s -> System.out.println(s));
        // 年龄大于23 小30 的学生
        students.stream().filter(student -> student.getAge() >= 23 && student.getAge() <=30)
                .sorted((o1, o2) ->o2.getAge() - o1.getAge())
                .forEach(s -> System.out.println(s));

        Stream<String> l = Stream.of("张三", "李四");
        Stream<String> stringStream = Stream.of("自己昂三", "第三方的");
        Stream<String> concat = Stream.concat(l, stringStream); // 合并
        concat.forEach(s -> System.out.println(s));

        Student student = students.stream().min(((o1, o2) -> o1.getAge() - o2.getAge())).get(); // 获取年龄最小的
        Optional<String> s1 = students.stream().max((o1, o2) -> o1.getAge() - o2.getAge()).map(s -> s.getName());
        long count = students.stream().filter(s -> s.getAge() == 26).count();  // 获取数量

        List<Student> collect = students.stream().filter(s -> s.getAge() == 26).collect(Collectors.toList());
        System.out.println(collect);
        System.out.println(count);
        System.out.println(s1);
        System.out.println(student);

    }
}
